<template>
  <div class="topNav">
      <img src="/src/assets/logo.gif"  class="logo" @click="goHome" />
    <ul class="menu">
      <li>
        <router-link to="/doc">文档</router-link>
      </li>
    </ul>
    <svg class="toggleAside" @click="toggleAside" v-if="toggleMenuButtonVisible">
      <use xlink:href="#icon-caozuo-caidan"></use>
    </svg>
  </div>
</template>

<script lang="ts">
import {inject, Ref} from "vue";
import {router} from "../router";

export default {
  name: "TopNav",
  props: {
    toggleMenuButtonVisible: {
      type: Boolean,
      default: false
    }
  },
  setup() {
    const asideVisible = inject<Ref<boolean>>('asideVisible')
    const toggleAside = ()=> {
      asideVisible.value = !asideVisible.value
    }
    const goHome = () => {
      router.push('/')
    }
    return {toggleAside,goHome}
  }
}
</script>

<style lang="scss" scoped>
.topNav {
  display: flex;
  padding: 16px;
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  z-index: 1;
  justify-content: center;
  align-items: center;

  .logo {
    width: 48px;
    height: 48px;
    margin-right: auto;
    background: inherit;
    transform: rotateY(180deg)
  }

  > .menu {
    display: flex;
    white-space: nowrap;
    flex-wrap: nowrap;

    > li {
      margin: 0 1em;
    }
  }

  > .toggleAside {
    display: none;
    width: 24px;
    height: 24px;
    background: inherit;
    position: absolute;
    left: 16px;
    top: 50%;
    transform: translateY(-50%);
    &:hover {
      border-bottom: 1px solid;
      cursor: pointer;
    }
  }

  @media (max-width: 500px) {
    > .menu {display: none}
    > .logo {margin: 0 auto}
    > .toggleAside {display: inline-block}
  }
}
</style>
